/**
 * Description:该类主要用于创建一个标签
 * Copyright: 成都和为科技有限公司 2012
 */

function CheckBoxGroup() {}

CheckBoxGroup.inherit(Container);

/**
 * 初始化方法
 */
CheckBoxGroup.prototype.init = function () {
	CheckBoxGroup.base.init.call(this);
}

CheckBoxGroup.prototype.create = function() {
	this._html = document.createElement("div");
    $(this._html).addClass("checkbox");
}

CheckBoxGroup.prototype.initLoad = function() {
	CheckBoxGroup.base.initLoad.call(this);
	var othis = this;
    $("input", this.getHTML()).bind("change", function(e){
        othis.triggerAttributeEvent("onchange");
    });
}

/**
 * 获取当前控件的值。需要提交到数据库
 */
CheckBoxGroup.prototype.getValue = function(){
	var values = new Array();
	var oItems = this.getElements();
	for (var item in oItems) {
		var oItem = oItems[item];
		if(oItem.getType() !="CheckBox"){
			continue;
		}
		if (oItem.hasChecked()) {
			var text = oItem.getText();
			var value = oItem.getValue();
			var oValue = new Object();
			oValue["text"] = text;
			oValue["value"] = value;
			values.push(oValue);
		}
	}
	return values;
}

/**
 * 设置值
 * @param {} sValue
 */
CheckBoxGroup.prototype.setValue = function(sValue) {
	if (!sValue || sValue == "") {
		this.clearSelect();
		return;
	}
	this.clearSelect();
	for (var i = 0 ; i < sValue.length ; i++) {
		var value = sValue[i]["value"];
		$("input[value = " + value + "]",this._html).each(function(){
			this.checked = true;
		});
	}
}


CheckBoxGroup.prototype.clearSelect = function() {
	$("input", this._html).each(function(){
		this.checked = false;
	});
}

/**
 * 设置为可编辑
 */
CheckBoxGroup.prototype.setEnable = function(){
	$("input",this._html).each(function() {
		this.disabled = false;
	});
	this._disable = false;
}

/**
 * 设置为只读
 */
CheckBoxGroup.prototype.setDisable = function(){
	$("input",this._html).attr("disabled","true");
	this._disable = true;
}